package com.wuzuqing.android.eightdiagrams

import android.graphics.Color
import android.widget.TextView
import com.wuzuqing.android.eightdiagrams.base.BaseAdapter
import com.wuzuqing.android.eightdiagrams.base.BaseViewHolder
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaItem
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaModel
import com.wuzuqing.android.eightdiagrams.utils.DataUtils

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 26.7.24 10:12 AM
 * @Description: 请写描述
 */
class QiMenDunJiaV2Adapter(
    var menBaGua: QiMenDunJiaModel? = null,
    var isShowOrigin: Boolean = false
) :
    BaseAdapter<QiMenDunJiaItem>(R.layout.item_qimendunjia) {

    var normalColor: Int = Color.parseColor("#333333")
    var poGongColor: Int = Color.parseColor("#FF613F")
    var ruMuColor: Int = Color.parseColor("#1CD83F")
    var xingColor: Int = Color.parseColor("#FF61D5")
    fun changeShowState(flag: Boolean) {
        if (isShowOrigin == flag) {
            return
        }
        isShowOrigin = flag
        notifyDataSetChanged()
    }

    private fun getSx(zhi:String ):String{
        return when(zhi){
            "午" -> return "午马"
            "未申" -> return "未羊申猴"
            "酉" -> return "酉鸡"
            "戌亥" -> return "戌狗亥猪"
            "子" -> return "子鼠"
            "丑寅" -> return "丑牛寅虎"
            "卯" -> return "卯兔"
            "辰巳" -> return "辰龙巳蛇"
            else -> return zhi
        }
    }
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val item = getItem(position) ?: return
        val shenNum = DataUtils.getShenBall(item.shen)
        val menNum = DataUtils.getMenBall(item.men)
        val xingNum = DataUtils.getJiuXingBall(item.xing)
        if (isShowOrigin) {
            item.also {
                holder.setText(R.id.tv_shen, it.shen)
                if (isShowOrigin) {
                    holder.setText(R.id.tv_men, "${it.originMen}\n${it.men}")
                    holder.setText(R.id.tv_xing, "${it.originXing}\n${it.xing}")
                } else {
                    holder.setText(R.id.tv_men, "${it.men}${DataUtils.getMenBall(it.men)}")
                    holder.setText(R.id.tv_xing, "${it.xing}${DataUtils.getJiuXingBall(it.xing)}")
                }

                if (it.isPoGong) {
                    holder.getView<TextView>(R.id.tv_men).setTextColor(poGongColor)
                } else {
                    holder.getView<TextView>(R.id.tv_men).setTextColor(normalColor)
                }

                holder.setText(R.id.tv_dipangan, "${it.diPanGan}${it.diPanCangGan}")
                holder.setText(R.id.tv_tianpangan, it.tianPanGan)

                holder.setText(R.id.tv_gua_shu, it.flagStr)
                holder.setText(R.id.tv_gua, "${it.gua}${it.gongNum}\n${getSx(it.diPanZhi)}")
            }
            return
        }
        //癸戊-凶　　　巽-東南
        // 景門-吉
        // 天任(休)-凶
        // 勾陳-凶
        // 七赤
        // 格局:六儀擊刑-凶
        item.also {
            val gan: String = DataUtils.getDunJiaItemGan(it)
            val menLuoGong = DataUtils.getDunJiaItemMenLuoGong(it)
            val xingLuoGong = DataUtils.getDunJiaItemXingLuoGong(it)
            val shenLuoGong = DataUtils.getDunJiaItemShenLuoGong(it)
            holder.setText(R.id.tv_gua, "${menNum}$menLuoGong\n${xingNum}$xingLuoGong\n${shenNum}$shenLuoGong\n${gan
            }${getSx(it.diPanZhi)}")
            holder.setText(R.id.tv_shen, "")
            holder.setText(R.id.tv_men, "")
            holder.setText(R.id.tv_xing, "")
            holder.setText(R.id.tv_dipangan, "")
            holder.setText(R.id.tv_tianpangan, "")
            holder.setText(R.id.tv_gua_shu, "")
        }
    }
}